<?php
if ( !SessionUtil::getVar(constant('SESSION_KEY_MEM_HAS_LOGIN'))) {
	ob_clean();
	header('Location:menbera.php');
	exit();
}
include(dirname(__FILE__).'/top-bottom-share-data.php');
$dt = new DataTable(constant('DB_TABLE_MEMBER'));
$act = isset($_REQUEST['act'])?$_REQUEST['act']:'';

$mem_id = SessionUtil::getVar(constant('SESSION_KEY_MEM_USER_ID'));
$GLOBALS['error_message'] = '';
if ( $act == 'save' ) {
	$member_data = $_REQUEST;
	$member_data['id'] =  SessionUtil::getVar(constant('SESSION_KEY_MEM_USER_ID'));
	if ( strlen($member_data['password']) > 0 ) {
		//check old password
		$row = $dt->get($mem_id);
		if ( $row['password'] == md5($member_data['oldpassword'])) {
			$member_data['password'] = md5($member_data['password']);
		}else{
			$GLOBALS['error_message'] = '舊密碼錯誤';
		}
		
	}else{
		unset($member_data['password']);
	}
	unset($member_data['email']);
	unset($member_data['display_name']);
	if ( $GLOBALS['error_message'] == ''){
	$dt->save($member_data);
	}
}

$GLOBALS['PAGE_ROW_DATA'] = $dt->get($mem_id);
?>